package com.mask.stream;


import com.mask.stream.pojo.Product;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ProductTest {

    public static List<Product> products = new ArrayList<>();

    static{
        products.add(new Product(1001,"电子产品","小米手机",1999.0,26));
        products.add(new Product(1003,"生活用品","牙膏",19.0,20));
        products.add(new Product(1002,"零食","麦芽糖",9.0,30));
        products.add(new Product(1005,"医疗用品","口罩",18.0,99));
        products.add(new Product(1004,"健身器材","跳绳",21.0,9));
        products.add(new Product(1007,"养生产品","明目茶",17.0,24));
        products.add(new Product(1006,"衣服","以纯牛仔裤",149.0,44));
        products.add(new Product(1008,"鞋子","鸿星尔克",199.0,10));
        products.add(new Product(1009,"汽车","比亚迪宋",99999.0,60));
        products.add(new Product(1010,"虚拟货币","比特币",9999.0,100));

    }

    public static void main(String[] args) {


        // 过滤出商品单价>100元的商品且库存>5件的商品
        // 对过滤出的商品按照库存进行排序
        // 取前3名
        // 映射 商品的名称和分类
        List<String> stringStream = products.stream()
                .filter(e -> e.getPrice() > 100)
                .filter(e -> e.getStock() > 5)
                .sorted((e, f) -> {
                    return e.getStock().compareTo(f.getStock());
                })
                .limit(3)
                .flatMap(e -> Stream.of(e.getName(),e.getCategory(),"===="))
                .collect(Collectors.toList());


        // 输出满足条件的信息
        stringStream.forEach(System.out::println);
    }

}
